package com.ssm.controller.admin;


import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.aspectj.internal.lang.annotation.ajcDeclareAnnotation;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ssm.controller.SSMController;
import com.ssm.model.bean.SsmWebSetting;
import com.ssm.model.mapper.ActionMapper;
import com.ssm.model.mapper.MenuMapper;
import com.ssm.model.mapper.WebSettingMapper;
import com.ssm.util.SSMUtil;

import tk.mybatis.mapper.entity.Example;
import tk.mybatis.mapper.entity.Example.Criteria;

/**
 * 网站管理页控制器
 * @author WWT<245108903@qq.com>
 * @version 2016/1/29
 * */

@Controller
@RequestMapping(value="websetting")
public class WebManageController extends AdminBaseController<SsmWebSetting> {

	/**
	 * 显示网站设置列表
	 * @author 危文涛<245108903@qq.com>
	 * @version 2016年2月1日 下午10:50:47
	 *
	 * @param request
	 * @param response
	 * @return
	 */
	
	@RequestMapping(value="index")
	public String index(HttpServletRequest request, HttpServletResponse response)
	{
		request.setAttribute("WEB_TITLE","网站设置列表");
		this.List2Table(WebSettingMapper.class,null,request,false);	
		return "websetting/index";
	}
	
	/**
	 * 添加&修改&查看网站设置
	 * @author 危文涛<245108903@qq.com>
	 * @version 2016年2月1日 下午10:51:03
	 *
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value="edit")
	public String editSetting(HttpServletRequest request, HttpServletResponse response,SsmWebSetting setting)
	{
		WebSettingMapper webSettingMapper=M.getMapper(WebSettingMapper.class);
		if(request.getMethod()=="POST")//修改&添加网站设置
		{
			if(setting.getId()==null)//添加
			{
				 setting.setCreatetime(nowTime().toString());
				 webSettingMapper.insert(setting);
				 request.setAttribute("item",setting);
				 request.setAttribute("WEB_TITLE", "查看网站设置");
			}
			else//编辑
			{
				 setting.setAlerttime(nowTime().toString());
				 setting.setAlertuserid(this.getUserID(request));
				 webSettingMapper.updateByPrimaryKeySelective(setting);
				 return "redirect:index";
			}
		}
		else//显示指定网站设置
		{
			Integer id=null;
			if(request.getParameter("id")!=null)
				id=Integer.parseInt(request.getParameter("id"));
			if(id==null)
			{
				request.setAttribute("WEB_TITLE", "添加网站设置");
			}
			else
			{
				SsmWebSetting webSetting=webSettingMapper.selectByPrimaryKey(id);
				request.setAttribute("item",webSetting);
				request.setAttribute("WEB_TITLE", "编辑网站设置");
			}
		}
		return "websetting/edit";
	}
	
	
	@RequestMapping(value="changeStatus")
	public String changeStatus(HttpServletRequest request)
	{
		changeStatus(WebSettingMapper.class,request);
		return "redirect:index";
	}
	
	
}
